package com.ruoyi.project.jiaqin.questionlikes.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.questionlikes.domain.MemberQuestionLikes;
import com.ruoyi.project.jiaqin.questionlikes.service.IMemberQuestionLikesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户点赞问题Controller
 *
 * @author admin
 * @date 2021-02-02
 */
@Controller
@RequestMapping("/jiaqin/questionlikes")
public class MemberQuestionLikesController extends BaseController
{
    private String prefix = "jiaqin/questionlikes";

    @Autowired
    private IMemberQuestionLikesService memberQuestionLikesService;

    @RequiresPermissions("jiaqin:questionlikes:view")
    @GetMapping()
    public String questionlikes()
    {
        return prefix + "/questionlikes";
    }

    /**
     * 查询用户点赞问题列表
     */
    @RequiresPermissions("jiaqin:questionlikes:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberQuestionLikes memberQuestionLikes)
    {
        startPage();
        List<MemberQuestionLikes> list = memberQuestionLikesService.selectMemberQuestionLikesList(memberQuestionLikes);
        return getDataTable(list);
    }

    /**
     * 导出用户点赞问题列表
     */
    @RequiresPermissions("jiaqin:questionlikes:export")
    @Log(title = "用户点赞问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberQuestionLikes memberQuestionLikes)
    {
        List<MemberQuestionLikes> list = memberQuestionLikesService.selectMemberQuestionLikesList(memberQuestionLikes);
        ExcelUtil<MemberQuestionLikes> util = new ExcelUtil<MemberQuestionLikes>(MemberQuestionLikes.class);
        return util.exportExcel(list, "questionlikes");
    }

    /**
     * 新增用户点赞问题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户点赞问题
     */
    @RequiresPermissions("jiaqin:questionlikes:add")
    @Log(title = "用户点赞问题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberQuestionLikes memberQuestionLikes)
    {
        return toAjax(memberQuestionLikesService.insertMemberQuestionLikes(memberQuestionLikes));
    }

//    /**
//     * 修改用户点赞问题
//     */
//    @GetMapping("/edit/{memberId}")
//    public String edit(@PathVariable("memberId") String memberId, ModelMap mmap)
//    {
//        MemberQuestionLikes memberQuestionLikes = memberQuestionLikesService.selectMemberQuestionLikesById(memberId,);
//        mmap.put("memberQuestionLikes", memberQuestionLikes);
//        return prefix + "/edit";
//    }

    /**
     * 修改保存用户点赞问题
     */
    @RequiresPermissions("jiaqin:questionlikes:edit")
    @Log(title = "用户点赞问题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberQuestionLikes memberQuestionLikes)
    {
        return toAjax(memberQuestionLikesService.updateMemberQuestionLikes(memberQuestionLikes));
    }

    /**
     * 删除用户点赞问题
     */
    @RequiresPermissions("jiaqin:questionlikes:remove")
    @Log(title = "用户点赞问题", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberQuestionLikesService.deleteMemberQuestionLikesByIds(ids));
    }
}
